﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.SharePoint.Portal.WebControls;
using Microsoft.Office.Server;
using Microsoft.SharePoint.Utilities;
using Microsoft.Office.Server.Infrastructure;
using System.Web;
using Microsoft.Office.Server.UserProfiles;
using System.Web.UI;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Utilities;

namespace SharePoint.MySpace
{
    public class MySpaceLink : UserControl // MySiteLinkUserControl
    {
        // Fields
        protected HyperLink hlMySite;
        protected Literal hlMySiteSpacerPrefix;
        protected Literal hlMySiteSpacerSuffix;


        public MySpaceLink()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            this.SetControl();
           
            base.OnInit(e);
        }


        protected void SetControl()
        {

            if (SPUrlUtility.IsUrlRelative(hlMySite.NavigateUrl))
            {
                ServerContext current = ServerContext.Current;
                UserProfileManager mgr = new UserProfileManager(current);
                string str = SPUrlUtility.CombineUrl(mgr.MySiteHostUrl ,hlMySite.NavigateUrl);
                hlMySite.NavigateUrl = str;
            }
        }



        internal static string EnsureNoTrailingSlash(string strUrl)
        {
            char[] trimChars = new char[] { '/' };
            return strUrl.TrimEnd(trimChars);
        }

    }

}
